package com.intct.hbase.ddl.table;

import com.intct.hbase.ddl.namespace.AbsNamespace;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;

import java.io.IOException;

/**
 * @author gufg
 * @since 2025-07-11 15:50
 */
public class Truncate extends AbsNamespace {
    @Override
    public void execCommand(Admin admin) throws IOException {
        // truncateTable(TableName tableName, boolean preserveSplits)
        TableName tableName = TableName.valueOf("intct82", "t03");

        // API中truncate table不会自动禁用，必须要手动禁用
        if (!admin.isTableDisabled(tableName)) {
            admin.disableTable(tableName);
        }
        // 清空表，并且设置为保留预分区(第二个参数需要设置为true，false不需要留预分区)
        admin.truncateTable(tableName, false);
    }

    public static void main(String[] args) throws IOException {
        new Truncate().start();
    }
}
